package algorithm;

public class leetcode_0035 {
    public int searchInsert(int[] nums, int target) {

        int len=nums.length;
        if(target<nums[0]) return 0;
        if(target>nums[len-1]) return len;
        return search(nums,0,len-1,target);
    }
    public int search(int[] nums,int left,int right,int target){
        if(left==right)return left;
        int mid=(left+right)/2;
        if(nums[mid]==target){
            return mid;
        }
        else if(nums[mid]<target){
            return search(nums,mid+1,right,target);
        }
        else{
            return search(nums,left,mid,target);
        }
    }
}
